﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Catchbase.TestTools.UTest
{
    [TestClass]
    public class DependenciesTest
    {
        [TestMethod]
        public void Objects_ContainExactCtorArguments()
        {
            var inj = new Dependencies<ComplexInjTestHelper>();
            inj.SetFuncInjection(new object());
            inj.Objects.First().MustBeInstanceOf(typeof(SimpleArgument));
            inj.Objects.Last().MustBeInstanceOf(typeof (Func<Object>));
            inj.Objects.MustSize(2);
        }

        [TestMethod]
        public void SetFuncInjection_MustNotAddTwice()
        {
            var inj = new Dependencies<ComplexInjTestHelper>();
            inj.SetFuncInjection(new object());
            inj.SetFuncInjection(new object());
            var func = (Func<Object>)inj.Objects.Last();
            func().MustBeInstanceOf(typeof(Object));

        }

        [TestMethod]
        public void Objects_ContainsWorkingFuncOfT()
        {
            var inj = new Dependencies<ComplexInjTestHelper>();
            inj.SetFuncInjection(new object());
            var func = (Func<Object>) inj.Objects.Last();
            func().MustBeInstanceOf(typeof(Object));
        }

        [TestMethod]
        public void GetMock_ReturnsSimpleCtorArguments()
        {
            var inj = new Dependencies<SimpleInjTestHelper>();
            inj.GetMock<SimpleArgument>().MustBeInstanceOf(typeof(Mock<SimpleArgument>));
        }

        [TestMethod]
        public void GetMock_ReturnsTFromFuncT()
        {
            var inj = new Dependencies<ComplexInjTestHelper>();
            inj.GetMock<SimpleArgument>().MustBeInstanceOf(typeof(Mock<SimpleArgument>));
            inj.GetMock<Object>().MustBeInstanceOf(typeof(Mock<Object>));
        }

        public class SimpleArgument{}
        public class SimpleInjTestHelper
        {
            public SimpleInjTestHelper(SimpleArgument s) { }
        }
        public class ComplexInjTestHelper
        {
            public ComplexInjTestHelper(SimpleArgument s, Func<object> o) { }
        }
    }
}